package com.xinqi.modules.exam.task.controller.admin;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.exam.task.dto.req.AsyncTaskProcessLogCreateDTO;
import com.xinqi.modules.exam.task.dto.req.AsyncTaskProcessLogQueryDTO;
import com.xinqi.modules.exam.task.dto.req.AsyncTaskProcessLogUpdateDTO;
import com.xinqi.modules.exam.task.dto.rsp.AsyncTaskProcessLogResultDTO;
import com.xinqi.modules.exam.task.service.AsyncTaskProcessLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 异步任务处理日志Admin控制层
 *
 * @author: linkai
 * @date: 2023/07/08
 */
@Tag(name = "Admin-异步任务处理日志", description = "异步任务处理日志Admin接口")
//@RestController
@RequestMapping("/admin/async-task-process-log")
@RequiredArgsConstructor
public class AsyncTaskProcessLogAdminController {
    private final AsyncTaskProcessLogService asyncTaskProcessLogService;

    /**
     * 异步任务处理日志-分页
     */
    @Operation(summary = "异步任务处理日志-分页")
    @GetMapping("/page")
    public R<PageInfo<AsyncTaskProcessLogResultDTO>> page(@ParameterObject AsyncTaskProcessLogQueryDTO dto) {
        PageInfo<AsyncTaskProcessLogResultDTO> page = asyncTaskProcessLogService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 异步任务处理日志-详情
     */
    @Operation(summary = "异步任务处理日志-详情")
    @GetMapping("/{id}")
    public R<AsyncTaskProcessLogResultDTO> findById(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        AsyncTaskProcessLogResultDTO dto = asyncTaskProcessLogService.findById(id);
        return R.data(dto);
    }

    /**
     * 新增异步任务处理日志
     */
    @Operation(summary = "新增异步任务处理日志")
    @PostMapping
    public R<Long> insert(@RequestBody AsyncTaskProcessLogCreateDTO dto) {
        return R.data(asyncTaskProcessLogService.insert(dto));
    }

    /**
     * 修改异步任务处理日志
     */
    @Operation(summary = "修改异步任务处理日志")
    @PutMapping("/{id}")
    public R<Boolean> update(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id,
                             @RequestBody AsyncTaskProcessLogUpdateDTO dto) {
        dto.setId(id);
        return R.data(asyncTaskProcessLogService.updateById(dto));
    }

    /**
     * 删除异步任务处理日志
     */
    @Operation(summary = "删除异步任务处理日志")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        return R.data(asyncTaskProcessLogService.deleteById(id));
    }
}
